<template>
  <div class="home">
    <div class="home-header">
      <img src="@/assets/imgs/logo.png" alt="">
      <van-search
      class="home-search"
        shape="round"
        placeholder="搜索"
      />
      <button class="home-open-app">打开App</button>
    </div>
    <div class="home-nav">
      <van-tabs class="home-nav-list" v-model:active="active">
        <van-tab title="推荐">
          <ul>
            <li v-for="(item, i) in recos" :key="i">
              <div>
                <div class="home-type">
                  <section class="left">
                    <img :src="item.icon" alt="">
                    <span class="title">{{item.tabName}}</span>
                    <span class="title-second">{{item.tabName}}</span>
                  </section>
                  <section class="right">
                    <span>更多</span>
                    <i class="back-common"></i>
                  </section>
                </div>
                <ul class="room-list">
                  <li v-for="(it, ind) in item.list" :key="ind">
                    <div>
                      <img :src="it.roomSrc" alt="roomSrc">
                      <span class="home-hot"><i class="back-common"></i>{{it.hn}}</span>
                      <span class="user-name"><i class="back-common"></i>{{it.nickname}}</span>
                    </div>
                    <p>{{it.roomName}}</p>
                  </li>
                </ul>
              </div>
              
            </li>
          </ul>
        </van-tab>
        <van-tab v-for="item in navs" :key="item.shortName" :title="item.name">
          内容 {{ item.name }}
        </van-tab>
      </van-tabs>
      <span class="home-more-nav back-common"></span>
    </div>
  </div>
</template>
<script>
import { getNavs, getMix } from '@/api'
import { reactive, toRefs } from 'vue'
export default {
  setup() {
    const state = reactive({
      active: 0,
      navs: [], // 导航列表数据
      recos: [] // 推荐直播列表数据
    })

    // 请求首页导航数据
    getNavs().then(res => {
      // console.log(res);
      state.navs = res.data
    })

    // 获取推荐直播列表数据
    getMix().then(res => {
      console.log(res);
      state.recos = res.data
    })

    return {
      ...toRefs(state)
    }
  }
}
</script>
<style lang="scss" scoped>
  .home-header {
    display: flex;
    align-items: center;
    height: 50px;
    padding: 0 10px;
    overflow: hidden;
    img {
      width: 76px;
      height: auto;
      flex-shrink: 0;
      height: 34px;
    }
    .home-search {
      margin-left: 10px;
    }
    .home-open-app {
      
      font-size: 12px;
      color: #fff;
      background-color: #ff5d23;
      border: none;
      outline: none;
      width: 80px;
      height: 30px;
      border-radius: 34px;
    }
  } 
  .home-nav {
    width: 100%;
    position: relative;
     height: calc(100% - 50px);
      overflow: auto;
    /deep/ .van-tabs__wrap {
      width: calc(100% - 54px);
    }
    .home-more-nav {
      position: absolute;
      width: 44px;
      height: 44px;
      background-image: url('../assets/imgs/category.png');
      
      top: 0;
      right: 10px;
    }
  }
  .home-type {
    display: flex;
    justify-content: space-between;
    height: 40px;
    align-items: center;
    padding: 0 10px;
    .left {
      display: flex;
      align-items: center;
      img {
        width: 18px;
        height: 18px;
        border-radius: 18px;
      }
      .title {
        margin: 0 15px;
      }
      .title-second {
        font-size: 12px;
        border: 1px solid #ff5d23;
        color: #ff5d23;
        padding: 5px 13px;
        border-radius: 22px;
      }
    }
    .right {
      display: flex;
      align-items: center;
      color: #999;
      font-size: 12px;
      i {
        width: 13px;
        height: 13px;
        background-image: url('../assets/imgs/icon-more.png');
        position: relative;
        top: -1px;
        margin-left: 10px;
      }
    }
    
  }
  .room-list {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0 5px;
    li {
      width: calc(50% - 2px);
      div {
        position: relative;
      }
      img {
        width: 100%;
        border-radius: 6px;
      }
      p {
        font-size: 12px;
        margin: 10px 0;
        font-weight: 200;
        width: 170px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .home-hot {
        position: absolute;
        top: 10px;
        right: 10px;
        color: #fff;
        font-size: 12px;
        display: flex;
        i {
          width: 12px;
          height: 12px;
          background-image: url('../assets/imgs/hotnum.png');
        }
      }
      .user-name {
        position: absolute;
        bottom: 10px;
        left: 10px;
        color: #fff;
        font-size: 12px;
        display: flex;
        i {
          width: 12px;
          height: 12px;
          background-image: url('../assets/imgs/iconfont-wo.png');
        }
      }
    }
  }
</style>
